package com.demo.task.ext

import com.demo.task.config.Config
import com.demo.task.socket.RemoteInterface
import com.demo.task.socket.SocketIO
import com.google.gson.Gson

private val gson by lazy { Gson() }

fun SocketIO.sendProgress(boxId: String, contentId: String) {
    val progress = mapOf(
        "boxId" to boxId,
        "contentId" to contentId,
        //"type" to window.type,
        //"qty" to window.qty,
        //"videoProgress" to -1,
        //"imageProgress" to -1
    )
    val params = mapOf(
        "type" to "progress",
        "message" to progress,
    )
    send(gson.toJson(params))
}

fun RemoteInterface.sendIds(ids: String) {
    val params = mapOf(
        "planids" to Config.planId,
        "planids" to ids,
        "controlids" to Config.controlId,
    )
    sendBasic(params)
}

fun RemoteInterface.sendError(
    type: String = MsgType.VIDEO.name,
    key: String = "",
    remark: String? = "",
) {
    val params = mapOf(
        "type" to type,
        "key" to key,
        "remark" to remark,
    )
    send(gson.toJson(mapOf("error" to params)))
}

enum class MsgType {
    VIDEO,
    DOWNLOAD,
}